package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.wemedia.WmUserControllerApi;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.common.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {
    @Autowired
    WmUserService wmUserService;


    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody WmUser wmUser) {

        //int a=1/0;
        //创建自媒体用户
        wmUserService.save(wmUser);



        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }


    @GetMapping("/findByName/{name}")
    @Override
    public WmUser findWmuserByName(@PathVariable("name") String name) {

        return wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName,name));
    }
}
